package com.ruoyi.erecord.samplebox.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erecord.samplebox.domain.vo.SampleboxImportDetailVo;
import com.ruoyi.erecord.samplebox.domain.bo.SampleboxImportDetailBo;
import com.ruoyi.erecord.samplebox.service.ISampleboxImportDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 导入明细
 *
 * @author cc
 * @date 2023-04-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erecord/sampleboxImportDetail")
public class SampleboxImportDetailController extends BaseController {

    private final ISampleboxImportDetailService iSampleboxImportDetailService;

    /**
     * 查询导入明细列表
     */
    @SaCheckPermission("erecord:sampleboxImportDetail:list")
    @GetMapping("/list")
    public TableDataInfo<SampleboxImportDetailVo> list(SampleboxImportDetailBo bo, PageQuery pageQuery) {
        return iSampleboxImportDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出导入明细列表
     */
    @SaCheckPermission("erecord:sampleboxImportDetail:export")
    @Log(title = "导入明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SampleboxImportDetailBo bo, HttpServletResponse response) {
        List<SampleboxImportDetailVo> list = iSampleboxImportDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "导入明细", SampleboxImportDetailVo.class, response);
    }

    /**
     * 获取导入明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("erecord:sampleboxImportDetail:query")
    @GetMapping("/{id}")
    public R<SampleboxImportDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSampleboxImportDetailService.queryById(id));
    }

    /**
     * 新增导入明细
     */
    @SaCheckPermission("erecord:sampleboxImportDetail:add")
    @Log(title = "导入明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SampleboxImportDetailBo bo) {
        return toAjax(iSampleboxImportDetailService.insertByBo(bo));
    }

    /**
     * 修改导入明细
     */
    @SaCheckPermission("erecord:sampleboxImportDetail:edit")
    @Log(title = "导入明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SampleboxImportDetailBo bo) {
        return toAjax(iSampleboxImportDetailService.updateByBo(bo));
    }

    /**
     * 删除导入明细
     *
     * @param ids 主键串
     */
    @SaCheckPermission("erecord:sampleboxImportDetail:remove")
    @Log(title = "导入明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSampleboxImportDetailService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
